#include<bits/stdc++.h>
using namespace std;
#define int long long

int n, s[15], b[15];
int ans = INT_MAX;

void dfs(int k, int cnt, int now_s, int now_b) {
	if (k == n) {
		if (cnt)	ans = min(ans, abs(now_s - now_b));
		return ;
	}
	dfs(k + 1, cnt + 1, now_s * s[k + 1], now_b + b[k + 1]);
	dfs(k + 1, cnt, now_s, now_b);
}

signed main() {
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> s[i] >> b[i];
	dfs(0, 0, 1, 0);
	cout << ans;
	return 0;
}
